<script setup>
import { nextTick, ref } from 'vue'
import { mainStore } from '@/store/mainStore.js'
const store = mainStore()

const radio1 = ref('目标')

const predefineColors = ref(['#ff4500', '#90ee90', '#ffd700', '#ff8c00', '#00ced1', '#1e90ff', '#c71585', '#FFE1FF', '#FFFF00', '#8B658B'])

let heightColor = ref(300)
nextTick(() => {
  const legend = document.querySelector('.legend-container').getBoundingClientRect()
  heightColor.value = Math.floor(legend.height - 30)
})
</script>

<template>
  <div class="legend-container">
    <!-- <div class="top">
      <p>图例</p>
    </div> -->
    <el-radio-group v-model="radio1">
      <el-radio-button size="small" label="目标"></el-radio-button>
      <el-radio-button size="small" label="来源"></el-radio-button>
    </el-radio-group>
    <div class="showMain">
      <div class="showTableEle" :style="{ maxHeight: heightColor + 'px' }">
        <el-table :data="radio1 == '目标' ? store.carTypeColor : store.srcColor" border style="width: 100%">
          <el-table-column type="index" label="序号" width="40" align="center" />
          <el-table-column prop="name" label="颜色" width="80" align="center"
            ><template v-slot="scope">
              <el-color-picker v-model="scope.row.color" :predefine="predefineColors"></el-color-picker>
            </template>
          </el-table-column>
          <el-table-column prop="type" label="类型" />
        </el-table>
      </div>
    </div>
  </div>
</template>

<style lang="less" scoped>
::v-deep .el-color-picker__trigger {
  width: 75px;
}
::v-deep .showTableEle .el-table .cell {
  max-width: 500px;
}
.legend-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.showMain {
  margin-top: 5px;
  overflow-y: auto;
}

.top {
  display: flex;
  align-items: center;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 10px;
}

.search {
  height: 30px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  > div {
    display: flex;
    align-items: center;
    margin-right: 20px;
    > div {
      padding: 0 6px;
      border-radius: 2px;
      cursor: pointer;
    }
    .btn_bg {
      margin-left: 10px;
    }
  }
  .btn {
    margin-right: 0;
  }
}

.showTableEle {
  padding-bottom: 20px;
}

.titleBtn {
  width: 100%;
  position: relative;
  display: flex;
  height: 30px;
  display: flex;
  align-items: flex-end;
  border: 1px solid #ccc;
  padding-right: 30px;

  .item {
    font-size: 12px;
    display: flex;
    align-items: center;
    height: 20px;
    background: white;
    margin-left: 4px;
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    border: 1px solid #ccc;
    border-bottom: none;
    padding: 0 2px;
    min-width: 50px;
    .delete {
      width: 12px;
      height: 12px;
      border-radius: 50%;
      background-color: #ccc;
      display: flex;
      justify-content: center;
      align-items: center;
      color: white;
      margin-left: 8px;
      // font-size: 10px;
      cursor: pointer;
      transform-origin: center;
      transform: rotate(45deg);
      > p {
        margin-left: 1px;
        margin-top: -2px;
      }
    }
  }
}

.showBtn {
  width: 30px;
  position: absolute;
  right: 0;
  bottom: 0;
  z-index: 99;
  cursor: pointer;
}

.showBtnBox {
  position: absolute;
  top: 30px;
  z-index: 99;
  background-color: white;
  height: 182px;
  width: 160px;
  padding: 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  box-shadow: rgba(0, 18, 38, 0.1) 0px 4px 10px 0px;
  .el-checkbox {
    margin-top: 8px;
  }
}
</style>
